//
// Created by cychen on 2023/3/7.
//

#include <cstring>
#include <string>
#include "../include/Utils.h"

using namespace std;

int char2int(char c) {
    int r = -1;
    if (islower(c)) {
        r = c - 'a';
    }
    //else if (isupper(c)) {
//        r = c - 'A';
//    }
    return r;
}


int getOutPutChar(vector<vector<string>> vec, char *result[]) {
    for (size_t i = 0; i < vec.size(); ++i) {
        string str_line;
        unsigned long long l = vec[i].size();
        for (unsigned long long j = 0; j < l; j++) {
            str_line += vec[i][j];
            if (j < l - 1) {
                str_line += " ";
            }
        }
        size_t length = str_line.size() + 1;
        result[i] = (char *) std::malloc(length);
        if (result[i]) {
            strcpy(result[i], str_line.c_str());
        }
    }
    return 0;
}

int vectorToCharArray(vector<string> &strings, char *result[]) {
    unsigned long long size = strings.size();
// Convert each string to char* pointer and store in char*[] array
    for (int i = 0; i < size; i++) {
        size_t length = strings[i].size() + 1;
        result[i] = (char *) std::malloc(length);
        if (result[i]) {
            strcpy(result[i], strings[i].c_str());
        }
    }
    return 0;
}


